<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-11-14
 * Time: ���� 3:52
 */

defined('ByShopWWI') or exit('Access Invalid!');
class findControl extends MobileControl{

    public function indexOp(){//发现、资讯
        $type = $_GET['type'];


        $condition = array();
        $condition['article_state'] = 3;

//        $page   = new Page();
//        $page->setEachNum(5);

        $order='article_publish_time desc';

        $model_article = Model('cms_article');
        $article_list = $model_article->getListWithClassName($condition, '0,10', $order);

        Tpl::output('article_list',$article_list);
        Tpl::output('totalPage',$model_article->getTotalPage());
        if($type=='information'){
            Tpl::showpage('find_information');
        }else{
            Tpl::showpage('find');
        }
    }

    public function indexPageOp(){//发现、资讯分页
        $pageNum = $_GET['curpage']+1;//当前页

        $model_article = Model('cms_article');
        $condition = array();
        $condition['article_state'] = 3;

        $page   = new Page();
        $page->setEachNum(5);
        $page->setNowPage($pageNum);

        $order='article_publish_time desc';
        $article_list = $model_article->getListWithClassName($condition,$page,$order);

        foreach($article_list as $k => $v){

            if(!$v['article_image']){
                $v['show_img'] = APP_TEMPLATES_URL.'/images/find2_02.jpg';
            }else{
                $image=unserialize($v['article_image']);
                $v['show_img'] = UPLOAD_SITE_URL.'/'.DIR_CMS.'/'.'article'.'/'.$image['path'].'/'.$image['name'];
            }

            $arr[] = $v;
        }
        $article_list = $arr;

        output_data(array('article_list' => $article_list,'curpage' => $pageNum));
    }

    public function hotOp(){//热门活动
        $model_article_class = Model('cms_article_class');
        $model_article = Model('cms_article');

        $article_class = $model_article_class->getOne(array('class_name'=>'热门活动'));

        $condition = array();
        $condition['article_state'] = 3;
        $condition['article_class_id'] = $article_class['class_id'];

        $article_list = $model_article->getListWithClassName($condition);

        Tpl::output('article_list',$article_list);
        Tpl::showpage('hot');
    }

    public function information_particularsOp(){//资讯详情
        $model_article = Model('cms_article');
        $article_id = intval($_GET['article_id']);

        $article_detail = $model_article->getOne(array('article_id'=>$article_id));

        $article_class = Model('cms_article_class')->getOne(array('class_id'=>$article_detail['article_class_id']));

        //计数加1
        $model_article->modify(array('article_click'=>array('exp','article_click+1')),array('article_id'=>$article_id));

        Tpl::output('article_detail',$article_detail);
        Tpl::output('article_class',$article_class);
        Tpl::showpage('find_information_particulars');
    }
}